GBML manual / Input

btn_held_frames

How many frames in a row button b has been held down, counting this one: 0 while it is up, 1 on the frame it goes down, 2 on the next. Use it for a charge shot (fire when it reaches 60 and the button comes up) or a long press.

Works differently on Game Boy - The Game Boy counts how long a button has been held up to 32,767 frames (about 9 minutes), and it counts from the first frame of the game.

Works differently on Game Boy Color - The Game Boy Color counts how long a button has been held up to 32,767 frames (about 9 minutes), and it counts from the first frame of the game.

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

btn_held_frames(b) -> int

Arguments

NameType
bbutton

Returns

int

Description

How many frames in a row button b has been held down, counting this one. It is 0 while the button is up, 1 on the frame it goes down, 2 on the next, and so on. btn_held only says "down right now"; this says for how long.

Use it for a charge shot (fire when the count reaches 60 and the button comes up) or for a long press.

Example

var charge = btn_held_frames(BTN_A);
if (charge >= 60) {
    x += 1;
}

After A has been held for a second (60 frames), the walker starts to move.

When counting begins

The first time any code calls btn_held_frames (or btn_buffered), the engine starts counting every button once a frame. So the count begins at that first call: a button that is already held then reads 1, because the frames before were not seen. Ask in a Step event or in a room's Create event and nothing is lost.

The small print

Cost

One small job at the end of every frame once the game has asked, a few steps for each of the ten buttons.

On the GBA

The first time any code calls this (or btn_buffered), the engine starts counting every button once a frame. So the count begins at that first call: a button already held then reads 1, because the frames before were not seen. Ask in a Step event or in a room's Create event and nothing is lost. It counts up to 65535 frames (about 18 minutes) and stops there. 60 frames is about a second. A game that never calls it has no counters at all. btn_held says only "down right now"; this one says for how long.

See also: btn_heldbtn_bufferedbtn_pressedbtn_released